package cases.boxes 
{
	import cases.control.MultipleButtonController;
	import com.greensock.TweenLite;
	import flash.display.MovieClip;
	import org.despair2D.control.KeyboardManager;
	import org.despair2D.renderer.display.DisplayUtil;
	import org.despair2D.ui.Button;
	import org.despair2D.ui.CheckBox;
	import org.despair2D.ui.PersonaState;
	import org.despair2D.ui.events.SelectedEvent;
	import org.despair2D.ui.events.ManipulateEvent;
	import org.despair2D.ui.LabelButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import org.despair2D.renderer.IAnime;
	import org.despair2D.ui.events.ManipulateEvent;
	import org.despair2D.ui.Fusion;
	import org.despair2D.ui.puppet.AnimePuppet
	import org.despair2D.ui.puppet.IPuppet;
	import org.despair2D.Despair;

	
public class BDemoBox extends PersonaState
{
	
	override public function enter() : void
	{
		this.group.move(110, 50)
		TweenLite.from(this.group, 1, { scaleX:0.2, scaleY:0.2 } )
		
		var M:MovieClip = DisplayUtil.createMovieClip('bg_A')
		this.group.createDisplayObjectContainerPuppet().addChild(M)
		
		this.group.setOrigin(M.width / 2, M.height / 2)
		
		
		var d_btn:Button
		//d_btn.view.rotation = 45;
		//d_btn.handler.addClickListener(_onClick);
		var l:int = 49;
			
		while (--l > -1)
		{
			d_btn = new Button('Btn_A');
			new MultipleButtonController(d_btn)
			//d_btn.rotation = 30;
			this.group.addFusion(d_btn);
			d_btn.move((l % 7) * 75 , int(l / 7) * 33);
			m_list.push(d_btn);
		}
		KeyboardManager.getInstance().getState().addPressListener('G', g);
		
		
	}

	

	override public function exit() : void
	{
		KeyboardManager.getInstance().getState().removePressListener('G', g);
		TweenLite.killTweensOf(this.group)
		m_list = null;
	}
	
	
	private function g():void
	{	
		var l:int = m_list.length
		if (l)
		{
			var index:int = l * Math.random();
			var box:Fusion = m_list[index];
			m_list[index].kill();
			m_list.splice(index, 1);
		}
		
		//DespairUtil.memory.gc();
		
		//trace('gc')
	}
	

	private var m_list:Array = []
	
	
	
	
}

}